
// Copyright (C) 2012 Luca Piccioni
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//  
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//  
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Diagnostics;
using System.Globalization;
using System.Text;
using System.Xml;

namespace Derm.Xml.Collada
{
	/// <summary>
	/// The TargetableFloat type is used to represent elements which contain a single float value
	/// which can be targeted for animation.
	/// </summary>
	[DebuggerDisplay("Value={Value}, SID={Sid}")]
	public class ColladaTargetableFloat : ColladaXmlSerializable
	{
		#region Constructors

		/// <summary>
		/// Construct a ColladaTargetableFloat.
		/// </summary>
		/// <param name="parent">
		/// The parent element containing this ColladaTargetableFloat.
		/// </param>
		public ColladaTargetableFloat(ColladaXmlSerializable parent) : base(parent)
		{
			
		}

		/// <summary>
		/// Construct a ColladaTargetableFloat.
		/// </summary>
		/// <param name="parent">
		/// The parent element containing this ColladaTargetableFloat.
		/// </param>
		public ColladaTargetableFloat(ColladaXmlSerializable parent, float value) : base(parent)
		{
			Value = value;
		}

		#endregion

		#region Targetable Float Information

		/// <summary>
		/// The element value.
		/// </summary>
		public float Value;

		/// <summary>
		/// The element sub-identifier.
		/// </summary>
		public string Sid;

		#endregion

		#region ColladaXmlSerializable Overrides

		/// <summary>
		/// Read the attribute of the current XML serializable.
		/// </summary>
		/// <param name="xmlReader">
		/// A <see cref="XmlReader"/> used for reading XML element attributes.
		/// </param>
		/// <remarks>
		/// <para>
		/// This method is called only in the case there are effectively attributes on XML element. Don't expect that this
		/// method will be called even when the attributes count is zero. This is very important, since the design doesn't
		/// allow object initialization using this method.
		/// </para>
		/// </remarks>
		public override void ReadAttributes(XmlReader xmlReader)
		{
			if (xmlReader  == null)
				throw new ArgumentNullException("xmlReader");

			string attribute;

			if ((attribute = xmlReader[ColladaAttributeSid]) != null)
				Sid = attribute;
		}

		/// <summary>
		/// Read the element text of the current XML serializable.
		/// </summary>
		/// <param name="xmlReader">
		/// A <see cref="XmlReader"/> used for reading child element. It is positioned at the start element.
		/// </param>
		public override void ReadText(XmlReader xmlReader)
		{
			if (xmlReader  == null)
				throw new ArgumentNullException("xmlReader");

			Value = Single.Parse(XmlHelper.ReadXmlTextElement(xmlReader), NumberFormatInfo.InvariantInfo);
		}

		/// <summary>
		/// Collada 'TargetableFloat' attribute name (1.4).
		/// </summary>
		private const string ColladaAttributeSid = "sid";

		#endregion
	}

	/// <summary>
	/// The TargetableFloat type is used to represent elements which contain a single float value
	/// which can be targeted for animation.
	/// </summary>
	[DebuggerDisplay("Value={Value}, SID={Sid}")]
	public class ColladaTargetableFloat3 : ColladaXmlSerializable
	{
		#region Constructors

		/// <summary>
		/// Construct a ColladaTargetableFloat3.
		/// </summary>
		/// <param name="parent">
		/// The parent element containing this ColladaTargetableFloat3.
		/// </param>
		public ColladaTargetableFloat3(ColladaXmlSerializable parent) : base(parent)
		{
			Value = new Vertex3f();
		}

		/// <summary>
		/// Construct a ColladaTargetableFloat3.
		/// </summary>
		/// <param name="parent">
		/// The parent element containing this ColladaTargetableFloat3.
		/// </param>
		/// <param name="value">
		/// </param>
		public ColladaTargetableFloat3(ColladaXmlSerializable parent, float[] value) : base(parent)
		{
			Value = new Vertex3f(value);
		}

		#endregion

		#region Targetable Float 3 Information

		/// <summary>
		/// The element value.
		/// </summary>
		public Vertex3f Value;

		/// <summary>
		/// The element sub-identifier.
		/// </summary>
		public string Sid;

		#endregion

		#region ColladaXmlSerializable Overrides

		/// <summary>
		/// Read the attribute of the current XML serializable.
		/// </summary>
		/// <param name="xmlReader">
		/// A <see cref="XmlReader"/> used for reading XML element attributes.
		/// </param>
		/// <remarks>
		/// <para>
		/// This method is called only in the case there are effectively attributes on XML element. Don't expect that this
		/// method will be called even when the attributes count is zero. This is very important, since the design doesn't
		/// allow object initialization using this method.
		/// </para>
		/// </remarks>
		public override void ReadAttributes(XmlReader xmlReader)
		{
			if (xmlReader  == null)
				throw new ArgumentNullException("xmlReader");

			string attribute;

			if ((attribute = xmlReader[ColladaAttributeSid]) != null)
				Sid = attribute;
		}

		/// <summary>
		/// Read the element text of the current XML serializable.
		/// </summary>
		/// <param name="xmlReader">
		/// A <see cref="XmlReader"/> used for reading child element. It is positioned at the start element.
		/// </param>
		public override void ReadText(XmlReader xmlReader)
		{
			if (xmlReader  == null)
				throw new ArgumentNullException("xmlReader");

			Value = new Vertex3f(XmlHelper.ReadXmlListOfFloats(xmlReader));
		}

		/// <summary>
		/// Collada 'TargetableFloat3' attribute name (1.4).
		/// </summary>
		private const string ColladaAttributeSid = "sid";

		#endregion
	}
}
